/**
 * Created by ls-PC on 2016/7/26.
 */

var moment = require('moment');
module.exports =function(orm,db){

    var Chatrecord =db.define('chatrecord',{
        useridto:{ type: 'number',rational : false  },
        useridfrom:{ type: 'number',rational : false  },
        contenttype:{ type: 'number',rational : false  },
        content:String,
        chattime:{ type: 'date', required: true, time: true }
    },{
        hooks: {
            beforeValidation: function () {
                this.chattime = new Date();
            }
        },
        methods: {
            serialize: function () {
                return {
                    id:this.id,
                    useridto:this.useridto,
                    useridfrom:this.useridfrom,
                    contenttype:this.contenttype,
                    content:this.content,
                    chattime : moment(this.createdAt).fromNow()
                }
            }
        }
    })
}